/*
 * Pratama Nur Wijaya (c) 2013 
 * 
 * Project       : Sound Of Indonesia
 * Filename      : MainActivity.java
 * Creation Date : Mar 30, 2013 time : 9:27:43 PM
 *
 */

package id.pratama.soundofindonesia;

import id.pratama.soundofindonesia.config.IApps_Data;
import id.pratama.soundofindonesia.config.IApps_Define;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.util.FPSLogger;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.view.KeyEvent;

public class MainActivity extends SimpleBaseGameActivity implements IApps_Data, IApps_Define
{
	public static BaseGameActivity	activity;

	private Camera					camera;
	private SceneManager			sceneManager;

	@Override
	public EngineOptions onCreateEngineOptions()
	{
		activity = this;
		camera = new Camera(0, 0, RES_WIDTH, RES_HEIGHT);
		EngineOptions en = new EngineOptions(true,
				ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
						RES_WIDTH, RES_HEIGHT), camera);
		en.getAudioOptions().setNeedsSound(true);
		return en;
	}

	@Override
	protected void onCreateResources()
	{
		mEngine.registerUpdateHandler(new FPSLogger());
		SceneManager.prepareSceneManager(activity, camera);
		sceneManager = SceneManager.getInstance();
	}

	@Override
	protected Scene onCreateScene()
	{
		sceneManager.setScene(SceneManager.SCENE_SPLASH);
		return SceneManager.loadedScene;
	}

	/*
	 * Method untuk menangani ketika user menekan tombol back
	 * 
	 * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			switch (SceneManager.currentScene)
			{
				case SceneManager.SCENE_SPLASH:
					break;
				case SceneManager.SCENE_MENU_UTAMA:
					finish();
					break;
				case SceneManager.SCENE_MENU_PILIH_ALAT_MUSIK:
					Utils.TRACE("Pindah ke scene utama");
					sceneManager.setScene(SceneManager.SCENE_MENU_UTAMA);
					break;
				case SceneManager.SCENE_MENU_PLAY_ALAT_MUSIK:
					Utils.TRACE("Pindah ke scene pilih alat musik");
					sceneManager.setScene(SceneManager.SCENE_MENU_PILIH_ALAT_MUSIK);
					break;
				case SceneManager.SCENE_INFO_ALAT_MUSIK:
					Utils.TRACE("Pindah ke play alat musik");
					sceneManager.setScene(SceneManager.SCENE_MENU_PILIH_ALAT_MUSIK);
					break;
				case SceneManager.SCENE_MENU_CREDIT:
					Utils.TRACE("Pindah ke Menu Utama");
					sceneManager.setScene(SceneManager.SCENE_MENU_UTAMA);
					break;
			}
		}
		return true;
	}
}
